package www.sofn.com;

import cn.hutool.json.JSONUtil;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import www.sofn.com.amap.ResultAmapVO;
import www.sofn.com.area.AreaService;
import www.sofn.com.utils.AddressUtils;

import java.net.URI;
import java.util.concurrent.TimeUnit;

//@SpringBootTest
public class test {
    @Resource
    private RestTemplate restTemplate;

    @Resource
    private AreaService areaService;

    private final static String AMAP_URL="https://restapi.amap.com/v3/config/district";
    private final static String KEY="b93fab647907b411e6467d7383a9077e";
//    @Test
    public void area(){
        UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromUriString(AMAP_URL);
        urlBuilder.queryParam("key", KEY)
                .queryParam("keywords", "北京")
                .queryParam("subdistrict", 2)
                .queryParam("extensions", "base");
        URI uri = URI.create(urlBuilder.toUriString());
        String resultStr = restTemplate.getForObject(uri, String.class);
        final ResultAmapVO resultAmapVO = JSONUtil.toBean(resultStr, ResultAmapVO.class);
        System.out.println(resultAmapVO.getDistricts().get(0));

    }

//    @Test
    public void testAreaChache() throws InterruptedException {
        areaService.findByParentId(0);
        TimeUnit.SECONDS.sleep(10);
        areaService.findByParentId(0);
    }



    @Test
    public void testAddress(){
        System.out.println(AddressUtils.getRealAddressByIP("192.168.4.89"));
    }


}
